import java.awt.event.KeyEvent;
import java.io.Serializable;

/** A class used to store informations about key bindings of one player.
 * 
 * @author crezax
 *
 */

public class Controls implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5684274772013470015L;
	private int left, right, up, down;
	
	
	/** A method, that returns key code of the key used to move player to the left.
	 * 
	 * @return key code of the key used to move player to the left.
	 */
	public int left(){
		return left;
	}
	
	/** A method, that returns key code of the key used to move player to the right.
	 * 
	 * @return key code of the key used to move player to the right.
	 */
	public int right(){
		return right;
	}
	
	/** A method, that returns key code of the key used to move player up.
	 * 
	 * @return key code of the key used to move player up.
	 */
	public int up(){
		return up;
	}
	
	/** A method, that returns key code of the key used to move player down.
	 * 
	 * @return key code of the key used to move player down.
	 */
	public int down(){
		return down;
	}
	
	/** A method used to set a new key that will be used to move player to the left.
	 * 
	 * @param left Code of the key that will be used to move player to the left.
	 */
	public void setLeft(int left){
		unbound(left);
		this.left = left;
	}
	
	/** A method used to set a new key that will be used to move player to the right.
	 * 
	 * @param right Code of the key that will be used to move player to the right.
	 */
	public void setRight(int right){
		unbound(right);
		this.right = right;
	}
	
	/** A method used to set a new key that will be used to move player up.
	 * 
	 * @param up Code of the key that will be used to move player up.
	 */
	public void setUp(int up){
		unbound(up);
		this.up = up;
	}
	
	/** A method used to set a new key that will be used to move player down.
	 * 
	 * @param down Code of the key that will be used to move player down.
	 */
	public void setDown(int down){
		unbound(down);
		this.down = down;
	}
	
	/**
	 * A method used to unbound all keys that are set to have a given key code.
	 * @param keyCode Key code that all keys that are set to should be unbound.
	 */
	private void unbound(int keyCode){
		if (left == keyCode) left = KeyEvent.VK_UNDEFINED;
		if (right == keyCode) right = KeyEvent.VK_UNDEFINED;
		if (up == keyCode) up = KeyEvent.VK_UNDEFINED;
		if (down == keyCode) down = KeyEvent.VK_UNDEFINED;
	}
}
